/*
 * Main.java
 *
 * Created on March 30, 2009, 5:06 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package im;

/**
 *
 * @author bluejack
 */

import im.node.MobileNode;
//import jade.core.AgentContainer;
import jade.core.ProfileImpl;
import jade.core.Runtime;
import jade.wrapper.AgentContainer;
import jade.wrapper.AgentController;
import jade.wrapper.ControllerException;

public class Main {
    
    /** Creates a new instance of Main */
    public Main() {
    }
    
    public static void main(String[] args) {
        int num_container = 2;
        System.out.println("ciao");
        
        Runtime imPlatform = Runtime.instance();
        //ResourceMonitor RM = new ResourceMonitor();
        AgentContainer imMainContainer = imPlatform.createMainContainer(new ProfileImpl());
        jade.wrapper.AgentContainer imContainers[] = new jade.wrapper.AgentContainer[num_container];
       // jade.wrapper.ContainerController imContainers[] = imPlatform.createAgentContainer(new ProfileImpl());
       
        //lancia ogni container dell'array
        for(int i=0;i<num_container;i++){
        	imContainers[i] = imPlatform.createAgentContainer(new ProfileImpl());
	        try {
	        	System.out.println("Main>\t\t[Iniziale]\tAvvio Container "+i);
				imContainers[i].start();
			} catch (ControllerException e1) {
				e1.printStackTrace();
			}
        }
        
         //lancia tutti gli agenti al posto giusto
        try {
        	
        	//lancia l'RMA nel main container
			AgentController RMA = imMainContainer.createNewAgent("RMA", "jade.tools.rma.rma", null);
			System.out.println("Main>\t\t[Iniziale]\tAvvio RMA");
			RMA.start();
                        
                        Object [] argv = new Object[1];
			for(int i=0;i<num_container;i++){
                            //lancia l'agente resource monitor nei container
                              argv[0] = new String("Container-"+i);
				jade.wrapper.AgentController rm = imContainers[i % num_container].createNewAgent(""+i, "im.node.MobileNode", argv);
				rm.start();                            
                        }
        }
            catch (Exception e) {
            e.printStackTrace();
        }
     
     imPlatform.shutDown();
     //System.out.println(imPlatform.getClass().getName());
        
        
    }
}
